﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication2.ViewModels;
using WpfApplication2.Views.Afiliado;
using WpfApplication2.SindicatoWebService;
using WpfApplication2.ViewModels.Afiliado;
using WpfApplication2.Helpers;


namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Page
    {
        public ERoles Rol { get; set; }

        public MainWindow(string username, ERoles rol)
        {
            Rol = rol;
            InitializeComponent();
            frmContent.NavigationUIVisibility = NavigationUIVisibility.Hidden;
            this.WindowTitle = String.Format("Bienvenido {0}!", username);
            ModalDialog.SetParent(ParentContainer);
            BajaAfiliadoDialog.SetParent(ParentContainer);
            DataContext = new MainWindowViewModel(Rol);

            NuevoAfiliadoViewModel afiliadoViewModel = new NuevoAfiliadoViewModel(frmContent, ModalDialog);
            frmContent.Content = new BuscarAfiliado(frmContent, ModalDialog, BajaAfiliadoDialog, Operacion.Editar);
        }
        
        private void btnNuevoAfiliado_Click(object sender, RoutedEventArgs e)
        {
            NuevoAfiliadoViewModel afiliadoViewModel = new NuevoAfiliadoViewModel(frmContent, ModalDialog);
            frmContent.Content = new NuevoAfiliado(frmContent,ModalDialog);
        }

        private void btnConsultarAfiliado_Click(object sender, RoutedEventArgs e)
        {
            NuevoAfiliadoViewModel afiliadoViewModel = new NuevoAfiliadoViewModel(frmContent, ModalDialog);
            frmContent.Content = new BuscarAfiliado(frmContent, ModalDialog, BajaAfiliadoDialog, Operacion.Consultar);
        }

        private void btnEditarAfiliado_Click(object sender, RoutedEventArgs e)
        {
            NuevoAfiliadoViewModel afiliadoViewModel = new NuevoAfiliadoViewModel(frmContent, ModalDialog);
            frmContent.Content = new BuscarAfiliado(frmContent, ModalDialog, BajaAfiliadoDialog, Operacion.Editar);
        }

        private void ShowHideBody(object sender, MouseButtonEventArgs e)
        {
            Border contenedorBorde = (sender as StackPanel).Parent as Border;
            StackPanel contenedor = contenedorBorde.Parent as StackPanel;
            Border bodyBorder = contenedor.Children[1] as Border;
            Border footer = contenedor.Children[2] as Border;
            StackPanel body = bodyBorder.Child as StackPanel;
            Image imgHeader = (sender as StackPanel).Children[0] as Image;
            if (bodyBorder.IsVisible)
            {
                imgHeader.Source = new BitmapImage(new Uri("Images/arrow_down.png", UriKind.Relative));
                bodyBorder.Visibility = Visibility.Collapsed;
                footer.Visibility = Visibility.Visible;
            }
            else
            {
                imgHeader.Source = new BitmapImage(new Uri("Images/arrow_up.png", UriKind.Relative)); ;
                bodyBorder.Visibility = Visibility.Visible;
                footer.Visibility = Visibility.Collapsed;

            }            
        }

        private void btnNuevoUsuario_Click(object sender, RoutedEventArgs e)
        {

        }

    }

}
